<include file="header" />
<div class="wraper normal" js="wapjs/meeting/js/meetinginvite">
	<div class="head clearfix">
		<if condition="$one['status'] eq 10 or $draft eq 1">
			<a href="{BEESCRM::U('/Meeting/MeetingPersonal/index',array('type' => 3,'account_id'=>$accountId))}" class="iconfont icon-zuo"></a>
			<else />
			<a href="{BEESCRM::U('/meeting/meeting/ucenter',array('audited' => 1,'account_id'=>$accountId))}" class="iconfont icon-zuo"></a>
		</if>
		<span class="head-name">填写基本信息</span>
		<input type="hidden" id="js_account_id" value="{BEESCRM:$accountId}">
	</div>

	<include file="new/statusbox" />

	<form>

		<div class="form-box">
			<p class="form-list">会议室/日期</p>
			<p class="form-list">
				<a href="javascript:void(0);" data-href="{BEESCRM::U('/meeting/MeetingRoom/roomList',array('account_id' => $accountId))}" class="text-normal select-room">
					<input placeholder="请预约会议室" name="room" value="{BEESCRM:$data.date}{BEESCRM:$data.weekday}{BEESCRM:$data.room_name}" readonly />
				</a>
			</p>
		</div>

		<div class="form-box">
			<p class="form-list">会议名称</p>
			<p class="form-list"><input placeholder="请选择会议名称" name="title" id="title" value="{BEESCRM:$data.title}" /></p>
		</div>

		<div class="form-box">
			<p class="form-list">会议时间</p>
			<p class="form-list">
				<input placeholder="请输入开始时间" name="start_time" id="start_time" value="{BEESCRM:$data.start_time}" />
			</p>
			<p class="form-list">
				<input placeholder="请输入结束时间" name="end_time" id="end_time" value="{BEESCRM:$data.end_time}" />
			</p>
		</div>

		<div class="lists">
			<if condition="!empty($departmentPath)">
				<input type="hidden" name="contactId" id="contactId" value="{BEESCRM:$contactId}">
				<a href="javascript:void(0);"  data-href="{BEESCRM::U('/Meeting/InviteUser/firstdepartment',array('account_id' => $accountId))}"  class="list-line text-green contact">
					<span class="iconfont icon-tianjia"></span> {BEESCRM:$departmentPath}
				</a>
				<else />
				<a href="javascript:void(0);"  data-href="{BEESCRM::U('/Meeting/InviteUser/firstdepartment',array('account_id' => $accountId))}"  class="list-line text-green contact">
					<span class="iconfont icon-tianjia"></span> 选择会议联系人
				</a>
			</if>
		</div>

		<div class="form-box">
			<p class="form-list"><input placeholder="请输入联系人电话" id="mobile" name="mobile" value="{BEESCRM:$mobile}"  /></p>
		</div>

		<div class="form-box">
			<a href="javascript:void(0);" class="form-list text-normal" style="display: block">会议服务<span class="iconfont icon-you pull-right modify-service"></span></a>

			<div class="flex-box text-12 facility <if condition='!$device[1]'>hide</if>">
				<p class="field">设施设备：</p>
				<p class="flex-item">
				<foreach name="device['1']" item="vo">
					{BEESCRM:$vo.device_name}*{BEESCRM:$vo.num} &nbsp; &nbsp; &nbsp; &nbsp;
				</foreach></p>
			</div>

			<div class="flex-box text-12 property <if condition='!$device[2]'>hide</if>">
				<p class="field">会务服务：</p>
				<p class="flex-item"><foreach name="device['2']" item="vo">
					{BEESCRM:$vo.device_name}*{BEESCRM:$vo.num}&nbsp; &nbsp; &nbsp; &nbsp;
				</foreach></p>
			</div>

			<div class="flex-box text-12 other <if condition='!$device[3]'>hide</if>">
				<p class="field">其他：</p>
				<p class="flex-item">
					<foreach name="device['3']" item="vo">
						{BEESCRM:$vo.device_name}*{BEESCRM:$vo.num}&nbsp; &nbsp; &nbsp; &nbsp;
					</foreach>
				</p>
			</div>
			<!--<div class="form-list text-gray modify-service modify <if condition='!empty($device[1]) or !empty($device[2]) or !empty($device[3])'><else />hide</if>">修改会议服务</div>-->
		</div>

		<input type="hidden" name="meeting_room_id" id="meetingRoomId" value="{BEESCRM:$data['meeting_room_id']}" />
		<input type="hidden" name="modify" id="modify" value="0" />
	</form>


	<a href="#" class="text-green block-space next-step">如需同时发布会议信息，请点此完善>></a>
	<div class="btn-box clearfix">
		<a href="javascript:void(0);" data-draft="0" class="btn bg-green directRelease">直接发布</a>
	</div>
</div>

<include file="new/servicemodify" />

<input type="hidden" name="limitDate" id="limitDate" value="{BEESCRM:$data.date}" />
<input type="hidden" name="limitStartTime" id="limitStartTime" value="{BEESCRM:$data.start_time}" />
<input type="hidden" name="limitEndTime" id="limitEndTime" value="{BEESCRM:$data.end_time}" />
<input type="hidden" name="basic_id" id="basic_id" value="{BEESCRM:$basicId}" />
<input type="hidden" name="advanceTime" id="advanceTime" value="{BEESCRM:$advance_time}" />


<script type="text/javascript" src="/assets/public/seajs/sea.js"></script>
<script enter="publicjs/public" id="confnode" async="async" src="/assets/public/config.js"></script>
<script type="text/javascript" src="/assets/public/jquery-2.1.0.min.js"></script>
<script>

	$(document).on('click','.contact',function() {  //选择联系人
		var data = {};
		data.mobile = $("#mobile").val();
		data.url = $(this).data('href');
		data.title = $("#title").val();

		var device = [];
		$(".count").each(function() {
			device.push([$(this).data('device_id'),$(this).val()]);
		})

		data.device = device;
		var accountId = $('#js_account_id').val();
		$.ajax({
			url:"/Meeting/MeetingRoom/saveMobile/step/two/account_id/" + accountId,
			data:data,
			type:'post',
			success:function(result){
				location.href = data.url;
			}
		});
	})

	$(document).on('click','.mbsc-fr-btn',function() { //修改预约时间
		var limitDate = $("#limitDate").val();
		var limitStartTime = $("#limitStartTime").val();
		var limitEndTime = $("#limitEndTime").val();

		var startStr = (limitDate + ' ' + limitStartTime);
		var start = Date.parse(new Date(startStr))/1000;

		var endStr = (limitDate + ' ' + limitEndTime);
		var end = Date.parse(new Date(endStr))/1000;

		var selectStartStr = (limitDate + ' ' + $("#start_time").val());
		var selectStart = Date.parse(new Date(selectStartStr))/1000;

		var selectEndStr = (limitDate + ' ' + $("#end_time").val());
		var selectEnd = Date.parse(new Date(selectEndStr))/1000;

		if(!(selectStart >= start && selectStart <= end) || !(selectEnd >= start && selectEnd <= end)) {
			fm.alert('请选择正确时间~');return false;
		}
	})

	var _height = $(document).height();
	$('.layermain').css('height',_height);

	$(document).on('click','.modify-service',function() { //修改服务
		$(".layer-wraper").show();
		$(".layermain").show();
	})

	$(document).on('click','.select-room',function() { //选择要预约的会议室

		var data = {};
		data.mobile = $("#mobile").val();
		data.url = $(this).data('href');
		data.title = $("#title").val();

		var device = [];
		$(".count").each(function() {
			device.push([$(this).data('device_id'),$(this).val()]);
		})

		data.device = device;
		var accountId = $('#js_account_id').val();
		$.ajax({
			url:"/Meeting/MeetingRoom/saveMobile/step/two/account_id/" + accountId,
			data:data,
			type:'post',
			success:function(result){
				location.href = '/meeting/MeetingRoom/roomList/account_id/{BEESCRM:$accountId}';
			}
		});

	})

	$(document).on('click','.directRelease',function() { //直接发布
		if(!$("input[name='room']").val().trim()){
			fm.alert('请选择会议室和日期~');return false;
		}

		if(!$("input[name='title']").val()) {
			fm.alert('请输入会议名称~');return false;
		}

		if(!$("#contactId").val()) {
			fm.alert('请选择联系人~');return false;
		}

		if(!$("#mobile").val()) {
			fm.alert('请输入电话~');return false;
		}

		//获取时间戳（单位秒）
		var date = '{BEESCRM:$data.date}';
		var stringTime1 = date + ' ' + $("#start_time").val();
		var stringTime2 = date + ' ' + $("#end_time").val();

		var start_timestamp = Date.parse(new Date(stringTime1)) / 1000;
		var end_timestamp = Date.parse(new Date(stringTime2)) / 1000;
		var current_timestatmp = Date.parse(new Date()) / 1000;
		if(!$("#start_time").val()) {
			fm.alert('请选择会议开始时间~');return false;
		}
		if(!$("#end_time").val()){
			fm.alert('请选择会议结束时间~');return false;
		}
		if (start_timestamp < current_timestatmp){
			fm.alert('会议的开始时间要大于当前时间~');return false;
		}
		if(start_timestamp >= end_timestamp){
			fm.alert('会议的开始时间不能大于或等于结束时间');return false;
		}

		var data = $('form').serialize();
		var is_draft = $(this).attr('data-draft'); //是否保存草稿

		data += "&is_draft=" + is_draft + "&start_time=" + stringTime1 + '&end_time=' + stringTime2;

		var advance_time = $("#advanceTime").val();
		var timestamp = Date.parse(new Date())/1000;
		var start = Date.parse(new Date('{BEESCRM:$data.date}' + ' ' + $("#start_time").val())) / 1000;

		if(start < (timestamp + 3600*advance_time)) {
			fm.alert('必须提前'+advance_time+'小时预约相关会议室');return false;
		}

		var device = [];
		$(".count").each(function() {
			device.push([$(this).data('device_id'),$(this).val()]);
		})
		data += "&device=" + device;

		var url = '/Meeting/MeetingInvite/directRelease/account_id/' + $('#js_account_id').val();
		$.ajax({
			url:url,
			data:data,
			type:'post',
			success:function(result){
				result = $.parseJSON(result);
				if(result.status == 'S'){
					location.href = "/Meeting/MeetingPersonal/index/type/3/account_id/" + $('#js_account_id').val();
				} else{
					fm.alert('发布失败');
				}
			}
		});
	})

	$('.next-step').click(function(){ //下一步
		if(!$("input[name='room']").val().trim()){
			fm.alert('请选择会议室和日期~');return false;
		}

		if(!$("input[name='title']").val()) {
			fm.alert('请输入会议名称~');return false;
		}

		if(!$("#contactId").val()) {
			fm.alert('请选择联系人~');return false;
		}

		if(!$("#mobile").val()) {
			fm.alert('请输入电话~');return false;
		}

		if(isNaN($("#mobile").val())) {
			fm.alert('请输入数字~');return false;
		}

		//获取时间戳（单位秒）
		var date = '{BEESCRM:$data.date}';
		var stringTime1 = date + ' ' + $("#start_time").val();
		var stringTime2 = date + ' ' + $("#end_time").val();

		var start_timestamp = Date.parse(new Date(stringTime1)) / 1000;
		var end_timestamp = Date.parse(new Date(stringTime2)) / 1000;
		var current_timestatmp = Date.parse(new Date()) / 1000;
		if(!$("#start_time").val()) {
			fm.alert('请选择会议开始时间~');return false;
		}
		if(!$("#end_time").val()){
			fm.alert('请选择会议结束时间~');return false;
		}
		if (start_timestamp < current_timestatmp){
			fm.alert('会议的开始时间要大于当前时间~');return false;
		}
		if(start_timestamp >= end_timestamp){
			fm.alert('会议的开始时间不能大于或等于结束时间');return false;
		}

		var data = $('form').serialize();
		var is_draft = $(this).attr('data-draft'); //是否保存草稿

		data += "&is_draft=" + is_draft + "&start_time=" + stringTime1 + '&end_time=' + stringTime2;

		var advance_time = $("#advanceTime").val();
		var timestamp = Date.parse(new Date())/1000;
		var start = Date.parse(new Date('{BEESCRM:$data.date}' + ' ' + $("#start_time").val())) / 1000;

		if(start < (timestamp + 3600*advance_time)) {
			fm.alert('必须提前'+advance_time+'小时预约相关会议室');return false;
		}

		var device = [];
		$(".count").each(function() {
			device.push([$(this).data('device_id'),$(this).val()]);
		})
		data += "&device=" + device;
		var url = '/Meeting/MeetingInvite/saveStep/step/one/account_id/' + $('#js_account_id').val();
		$.ajax({
			url:url,
			data:data,
			type:'post',
			success:function(result){
				if(result){
					if(is_draft == 1){
						location.href = "/Meeting/MeetingPersonal/index/type/3/account_id/" + $('#js_account_id').val();
					}else{
						location.href = "/Meeting/MeetingInvite/addInviteMeeting/step/two/account_id/" + $('#js_account_id').val();
					}
				}
			}
		});
	});

</script>
<include file="footer" />